import request from '@/utils/request'
const baseUrl = '/mall/address'

export function addAddress(address) {
  return request({
    url: `${baseUrl}/addAddress`,
    method: 'post',
    data: address
  })
}

export function getAddressById(id) {
  return request({
    url: `${baseUrl}/getById/${id}`,
    method: 'get'
  })
}

export function updateAddress(address) {
  return request({
    url: `${baseUrl}/updateAddress`,
    method: 'post',
    data: address
  })
}

// 分页获取用户的地址
export function getUserAddressPage(params) {
  return request({
    url: `${baseUrl}/getAllById/${params.userId}/${params.pageNum}/${params.pageSize}`,
    method: 'get'
  })
}

// 获取用户所有地址
export function getUserAddressList(userId) {
  return request({
    url: `${baseUrl}/getAllById/${userId}`,
    method: 'get'
  })
}

// 获取用户默认地址
export function getUserDefaultAddress(userId) {
  return request({
    url: `${baseUrl}/getDefaultAddress/${userId}`,
    method: 'get'
  })
}

// 删除地址
export function deleteAddress(addressId) {
  return request({
    url: `${baseUrl}/deleteAddress/${addressId}`,
    method: 'delete'
  })
}
